package good.idea.data.utils;


import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class MatcherUtils {

    public MatcherUtils() {

    }


    public static final String SPECWAY_VALID = "SPECWAY_VALID";//特殊处理  特殊校验处理
    public static final String SPECWAY_HANDLE = "SPECWAY_HANDLE";//特殊处理之后 重取返回值


    public static final String ENGLISH_NUMBER_IGNORECASE = "^[A-Za-z0-9_]+$";//大小写英文字母数字
    //	public static final String ENGLISH_IGNORECASE="^[A-Za-z_]+$";//大小写英文字母
    public static final String ENGLISH_IGNORECASE = "^[A-Za-z]+[A-Za-z\\s]*[A-Za-z]*$";//大小写英文字母
    public static final String ENGLISH_LOWER = "^[a-z_]+$";    //小写英文字母
    public static final String ENGLISH_UPPER = "^[A-Z_]+$";    //大写英文字母
    //	public static final String DATE_DEFAULT="^[0-9]{4}(((0[13578]|(10|12))(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)(0[1-9]|[1-2][0-9]|30)))$";	//日期
    public static final String DATE_DEFAULT = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229)";    //日期
    public static final String NUMBER = "^[0-9]+$";    //数字
    //public static final String NUMBER="^-?+[0-9]+(.[0-9]+)?$";	//数字
    public static final String PHONE = "(^(^\\d{3}-)?\\d{8}$)|(^1[0-9]{10}$)";
    public static final String CHINESE = "^[\\u4e00-\\u9fa5?]+$";//中文


    public static boolean matcherRegExp(String reg, String val) {
        if (val == null) {
            return false;
        }
        val = val.replace(".", "").replace("-", "");
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(val);
        if (matcher.matches()) {
            return true;
        } else {
            return false;
        }
    }


    public static Object ConvertObj(String propty, String value, Class<?> proptyType) {

        if (proptyType.equals(String.class)) {
            return value;
        } else if (proptyType.equals(Integer.class)) {
            return Integer.parseInt(String.valueOf(value));
        } else if (proptyType.equals(Double.class)) {
            value = value.replace("(", "");
            value = value.replace(")", "");
            return Double.parseDouble(String.valueOf(value));
        } else if (proptyType.equals(Long.class)) {
            return Long.parseLong(String.valueOf(value));
        } else if (proptyType.equals(Date.class)) {
            Date date = null;
            if ("NOW".equals(value)) {
                date = new Date();
            } else {
                date = LangUtils.parseDate(value);
            }
            return date;
        } else if (proptyType.equals(Short.class)) {
            return Short.parseShort(String.valueOf(value));
        } else if (proptyType.equals(Byte.class)) {
            return null;
        } else {

        }
        return proptyType;
    }


    public static String matcherDictVal(String kind, String text, String val) {
        //String str=CodeToDetail.getCode(kind,val,text);
        String value = "这里是字典表翻译";//COMMON.getZdbCode(kind, val, text);
        return value;
    }


}
